/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from '@mineadmin/form'
import hasAuth from '@/utils/permission/hasAuth.ts'
import MaDictSelect from '@/components/ma-dict-picker/ma-dict-select.vue'
import MaDictRadio from '@/components/ma-dict-picker/ma-dict-radio.vue'
import MaUploadImage from '@/components/ma-upload-image/index.vue'
import MaRemoteSelect from '@/components/ma-remote-select/index.vue'
import { attractionStatus, infoGroup } from '$/attractions/attraction-management/views/attractionInfo/data/common.tsx'
import { getAll as getTypeList } from '$/attractions/attraction-management/api/attractionType.ts'
import { getAll as getSpotList } from '$/attractions/attraction-management/api/attractionSpot.ts'
import { concat } from 'lodash-es'
import MaWangEditor from '$/attractions/attraction-management/components/MaWangEditor.vue'

export default function getFormItems(formType: 'add' | 'edit' = 'add', t: any, model: any): MaFormItem[] {
    

      return concat([
    { 
      label: '标题', 
      prop: 'title', 
      render: 'input', 
      renderProps: { 
        placeholder: '请输入信息标题'
      },
      itemProps: { 
        rules: [
          { required: true, message: '请输入标题' },
        ] 
      } 
    },
    { 
      label: '内容', 
      prop: 'intro', 
      render: () => MaWangEditor, 
      renderProps: { 
        height: 400,
        placeholder: '请输入信息内容...'
      }
    },
    { label: '信息分组', prop: 'group', render: () => MaDictRadio, renderProps: { placeholder: t('form.pleaseInput', { msg: '信息分组1活动2优惠3交通'}), data: infoGroup }, itemProps: { rules: [
    { required: true, message: '请输入信息分组' },
  ] } },
    { 
      label: '类型', 
      prop: 'type_id', 
      render: () => MaRemoteSelect, 
      renderProps: {
        api: getTypeList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            // 过滤type为2的数据（信息资讯类型）
            return response.data.list
              .filter((item: any) => item.type === 2)
              .map((item: any) => ({
                label: item.name,
                value: item.id
              }))
          }
          return []
        },
        placeholder: '请选择信息类型',
        clearable: true
      }, 
      itemProps: { 
        rules: [
          { required: true, message: '请选择信息类型' },
        ] 
      } 
    },
    { 
      label: '点位', 
      prop: 'spot_id', 
      render: () => MaRemoteSelect, 
      renderProps: {
        api: getSpotList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.name || `点位${item.id}`,
              value: item.id
            }))
          }
          return []
        },
        placeholder: '请选择点位',
        clearable: true
      }
    },
    { label: '封面', prop: 'cover_id', render: () => MaUploadImage, renderProps: { multiple: false } },
    { label: '是否显示', prop: 'status', render: () => MaDictRadio, renderProps: { placeholder: t('form.pleaseInput', { msg: '是否显示状态1正常2停止3时间字段决定,优先级高于时间控制'}), data: attractionStatus }, itemProps: { rules: [
    { required: true, message: '请输入选择显示' },
  ] } },
    { label: '排序', prop: 'sort', render: 'input', renderProps: { placeholder: t('form.pleaseInput', { msg: '排序'}) }, itemProps: { rules: [
    { required: true, message: '请输入排序' },
  ] } },
    { label: '开始时间', prop: 'start_time', render: 'DatePicker', renderProps: { placeholder: t('form.pleaseInput', { msg: '开始时间'}) }, itemProps: { rules: [
    { required: true, message: '请输入开始时间' },
  ] }, mode: 'date', showTime: true },
    { label: '结束时间', prop: 'end_time', render: 'DatePicker', renderProps: { placeholder: t('form.pleaseInput', { msg: '结束时间'}) }, itemProps: { rules: [
    { required: true, message: '请输入结束时间' },
  ] }, mode: 'date', showTime: true },
    { label: '扩展信息', prop: 'extension', render: 'input', renderProps: { placeholder: t('form.pleaseInput', { msg: '扩展信息'}) }, itemProps: { rules: [
    { required: false, message: '请输入扩展信息' },
  ] } },
  ]);
}
